package com.sajhasite.domain.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.sajhasite.domain.constant.CategoryType;

@Entity
@Table(name="post")

@NamedQueries({@NamedQuery(name="getLastNPosts",query="from Post post")})
public class Post extends BaseEntity{

	private Long postId;
	private String postType;
	private String title;
	private String body;
	
	private CategoryType categoryType;
	private Set<ChildPost> childPosts;
	private Date createdTimeStamp;
	private Date updatedTimestamp;
	private User user;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="post_id")
	public Long getPostId() {
		return postId;
	}
	public void setPostId(Long postId) {
		this.postId = postId;
	}
	@Column(name="body",length=1000,nullable=false)
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	@Column(name="post_type", length=100, nullable=true)
	public String getPostType() {
		return postType;
	}
	public void setPostType(String postType) {
		this.postType = postType;
	}
	@Column(name="title", length=100, nullable=false)
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name="category_type", length=100, nullable=false)
	@Enumerated(EnumType.STRING)
	public CategoryType getCategoryType() {
		return categoryType;
	}
	public void setCategoryType(CategoryType categoryType) {
		this.categoryType = categoryType;
	}
	@Column(name="created_timestamp", length=100, nullable=false)
	public Date getCreatedTimeStamp() {
		return createdTimeStamp;
	}
	public void setCreatedTimeStamp(Date createdTimeStamp) {
		this.createdTimeStamp = createdTimeStamp;
	}
	@Column(name="updated_timestamp", length=100, nullable=false)
	public Date getUpdatedTimestamp() {
		return updatedTimestamp;
	}
	public void setUpdatedTimestamp(Date updatedTimestamp) {
		this.updatedTimestamp = updatedTimestamp;
	}
	@ManyToOne
	@JoinColumn(name="user_id")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@OneToMany(mappedBy="post")
	public Set<ChildPost> getChildPosts() {
		return childPosts;
	}
	public void setChildPosts(Set<ChildPost> childPosts) {
		this.childPosts = childPosts;
	}
	
	
	
}
